package com.koron.css2.serviceManage.impl;

import com.koron.css2.ApplicationConfig;
import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.systemManage.bean.OperationTreeBean;
import com.koron.css2.systemManage.dto.UserAuthorityDto;
import com.koron.css2.systemManage.service.UserService;
import com.koron.util.Constant;
import com.koron.util.SpringContextHolder;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.stream.Collectors;

public class SysModuleTree implements ServerInterface {
	
	private UserService userService = SpringContextHolder.getBean(UserService.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);
		try {
			UserAuthorityDto userAuthority = userService.getUserAuthority(factory, userInfo, ApplicationConfig.getAppCustomerAppid(), req.getToken());
			List<OperationTreeBean> operations = userAuthority.getOperations();
			operations = operations.stream().filter(t -> t.getOpFlag() == 1).collect(Collectors.toList());
			info.setCode(Constant.MESSAGE_INT_SUCCESS);
			info.setDescription("success");
			info.setData(operations);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("查询快捷菜单出错");
			logger.error(e.getMessage(), e);
		}
		return info;
	}
}
